package com.nuanshui.framework.schedule.zk;

import com.github.zkclient.ZkClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ConcurrentHashMap;

/**
 * zk client 管理器
 * Created by hh on 9/8/15.
 */
public class ClientCacheManager {
    private static final Logger LOGGER = LoggerFactory.getLogger("schedule");
    private static final String PRE = "zk-schedule-";

    private static final ConcurrentHashMap<String, ZkClient> zkClientCache = new ConcurrentHashMap<String, ZkClient>();

    public static ZkClient getClient(String cxnString) {
        LOGGER.debug("get zookeeper client with {}", cxnString);
        String key = PRE + cxnString;
        if (zkClientCache.get(key) == null) {
            zkClientCache.put(key, new ZkClient(cxnString, 5000));
        }
        return zkClientCache.get(key);
    }

}
